% This subroutine calculates income differences between young and old
% generations.
%
% Used in the paper "Land Insecurity and Mobility Frictions," by Tasso
% Adamopoulos, Loren Brandt, Chaoran Chen, Diego Restuccia, and Xiaoyun
% Wei, prepared for publication at the Quarterly Journal of Economics.
%
% Last modified: March 3, 2024

dummy_ope_o = (dummy_old.*dummy_ope);
dummy_ope_y = ((1-dummy_old).*dummy_ope);

inc_diff_yo_u = sum(sum(log(ind_h).*(dummy_urban+dummy_pt_u).*(1-dummy_old)))...
    /(sum(sum((dummy_urban+dummy_pt_u).*(1-dummy_old)))+eps) - ...
    sum(sum(log(ind_h).*(dummy_urban+dummy_pt_u).*dummy_old))...
    /(sum(sum((dummy_urban+dummy_pt_u).*dummy_old))+eps);

inc_diff_yo_r = sum(sum(log(ind_h).*(dummy_rural+dummy_pt_r).*(1-dummy_old)))...
    /(sum(sum((dummy_rural+dummy_pt_r).*(1-dummy_old)))+eps) - ...
    sum(sum(log(ind_h).*(dummy_rural+dummy_pt_r).*dummy_old))...
    /(sum(sum((dummy_rural+dummy_pt_r).*dummy_old))+eps);

inc_diff_yo_ope = sum(sum(log(farm_y*p+eps).*dummy_ope_y))...
    /(sum(sum(dummy_ope_y))+eps) - ...
    sum(sum(log(farm_y*p+eps).*dummy_ope_o))...
    /(sum(sum(dummy_ope_o))+eps);